package org.ywf.common;

import org.ywf.common.enums.ResultEnumCode;

import java.io.Serializable;

public class R<T> implements Serializable {

    private String code;

    private String msg;

    private Boolean success;

    private T data;

    public R() {
    }

    public static R ok(){
        R r = new R();
        r.setCode(ResultEnumCode.SUCCESS.getCode());
        r.setMsg(ResultEnumCode.SUCCESS.getMsg());
        r.setSuccess(true);
        return r;
    }

    public static R error(){
        R r = new R();
        r.setCode(ResultEnumCode.FAIL.getCode());
        r.setMsg(ResultEnumCode.FAIL.getMsg());
        r.setSuccess(false);
        return r;
    }

    public static R setResult(ResultEnumCode resultEnumCode){
        R r = new R();
        r.setCode(resultEnumCode.getCode());
        r.setMsg(resultEnumCode.getMsg());
        return r;
    }

    public R<T> data(T data){
        this.setData(data);
        return this;
    }

    public R<T> msg(String msg){
        this.setMsg(msg);
        return this;
    }

    public R<T> code(String code){
        this.setCode(code);
        return this;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }
}
